const express = require("express");
const axios = require("axios");
const cors = require("cors");

const app = express();
const PORT = 3000;

// 使用 CORS 中间件
app.use(cors());

// 创建一个路由，代理请求
app.get("/api/weather", async (req, res) => {
  try {
    const response = await axios.get(`https://wis.qq.com/weather/common`, {
      params: {
        source: "pc",
        weather_type: "forecast_24h",
        province,
        city,
        county,
      },
    });
    res.json(response.data);
  } catch (error) {
    console.error("Error fetching weather data:", error);
    res.status(500).json({ error: "Failed to fetch weather data" });
  }
});

// 启动服务器
app.listen(PORT, () => {
  console.log(`服务启动 on http://localhost:${PORT}`);
});
